//
//  TeamSettingDetailCell.swift
//  NETeamUIKit
//
//  Created by Laura on 2024/8/7.
//


import UIKit

@objcMembers
open class TeamSettingDetailCell: NEBaseTeamSettingCell {
    /// 标题
    public lazy var subTitleLabel: UILabel = {
        let label = UILabel()
        label.textColor = .normalSubTitleColor
        label.font = NEConstant.defaultTextFont(14.0)
        label.translatesAutoresizingMaskIntoConstraints = false
        label.accessibilityIdentifier = "id.subTitleLabel"
        label.numberOfLines = 3
        label.lineBreakMode = .byTruncatingTail
        return label
    }()
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        selectionStyle = .none
        setupUI()
    }
    
    public required init?(coder: NSCoder) {
        super.init(coder: coder)
    }
    
    open func setupUI() {
        contentView.addSubview(titleLabel)
        contentView.addSubview(subTitleLabel)
        contentView.addSubview(arrowView)
        
        NSLayoutConstraint.activate([
            titleLabel.leftAnchor.constraint(equalTo: contentView.leftAnchor, constant: kScreenInterval+12),
            titleLabel.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 12),
            titleLabel.rightAnchor.constraint(equalTo: arrowView.leftAnchor, constant: -12),
            titleLabel.heightAnchor.constraint(equalToConstant: 22)
        ])
        
        NSLayoutConstraint.activate([
            subTitleLabel.topAnchor.constraint(equalTo: titleLabel.bottomAnchor, constant: 8),
            subTitleLabel.leftAnchor.constraint(equalTo: titleLabel.leftAnchor, constant: 0),
            subTitleLabel.widthAnchor.constraint(equalToConstant: UIScreen.main.bounds.size.width-86),
            subTitleLabel.heightAnchor.constraint(equalTo: contentView.heightAnchor, constant: -50),
        ])
                
        NSLayoutConstraint.activate([
            arrowView.topAnchor.constraint(equalTo: subTitleLabel.topAnchor),
            arrowView.rightAnchor.constraint(equalTo: contentView.rightAnchor, constant: -kScreenInterval-12),
            arrowView.widthAnchor.constraint(equalToConstant: 20),
            arrowView.heightAnchor.constraint(equalToConstant: 20)
        ])
    }
    
    override open func configure(_ anyModel: Any) {
        super.configure(anyModel)
        
        if let m = anyModel as? SettingCellModel {
            
            let paragraphStyle = NSMutableParagraphStyle()
            paragraphStyle.maximumLineHeight = 20
            paragraphStyle.minimumLineHeight = 20
            paragraphStyle.lineBreakMode = .byTruncatingTail
            
            let attributes: [NSAttributedString.Key: Any] = [
                .paragraphStyle: paragraphStyle
            ]
             
            subTitleLabel.attributedText = NSAttributedString(string: m.subTitle ?? "", attributes: attributes)
            
            if m.cellName == localizable("alias") {
                let attStr1 = NSMutableAttributedString(string: m.cellName ?? "", attributes: [
                    .font: UIFont.systemFont(ofSize: 16),
                    .foregroundColor: UIColor.normalTeamTitleColor,
                ])
                
                let attStr2 = NSAttributedString(string: " 仅客户经理、波波知了客服与专员可见", attributes: [
                    .font: UIFont.systemFont(ofSize: 13),
                    .foregroundColor: UIColor.normalOrangeColor,
                ])
                
                attStr1.append(attStr2)
                
                
                titleLabel.attributedText = attStr1
            }
        }
    }
}
